package com.example.arithmeticleetcode.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-05-07 11:27
 **/
public class Demo13 {

    public static void main(String[] args) {
        int[] nums1 = {1, 0, 0, 0, 1, 0, 0, 1}; // true
        int[] nums2 = {1, 0, 0, 1, 0, 1};// false
        int[] nums3 = {1, 1, 1, 1, 1};// true
        int[] nums4 = {0, 1, 0, 1};// true
        int[] nums5 = {1, 1, 1, 0};// false
        System.out.println(kLengthApart(nums1, 2));
        System.out.println(kLengthApart(nums2, 2));
        System.out.println(kLengthApart(nums3, 0));
        System.out.println(kLengthApart(nums4, 1));
        System.out.println(kLengthApart(nums5, 3));
    }


    public static boolean kLengthApart(int[] nums, int k) {
        int pre = -1;
        for (int i = 0, len = nums.length; i < len; i++) {
            if (nums[i] == 1) {
                if (pre != -1 && i - pre - 1 < k) return false;
                pre = i;
            }
        }
        return true;
    }
}
